/**
 * 考勤数据展示
 */

import Moment from "@/components/app/Moment";
import ByText from "@/components/ui/ByText";
import { Text, View } from "@tarojs/components";
import { convertSeconds } from "@/utils";

import { WorkerAttendanceRecord } from "@/types/attendance";

export default ({ source }: { source?: WorkerAttendanceRecord }) => {
  if (!source || source.workerHours === 0)
    return <ByText type="warning">无考勤记录</ByText>;

  const { workerHours, duration, workerStartDate, workerEndDate } = source;
  const { hour, min } = convertSeconds(workerHours, ["hour", "min"]);

  return (
    <View>
      <ByText size="sm" type="second">
        <Text>打卡{duration}天 </Text>
        <Text>
          共{hour ? hour + "小时" : ""}
          {min ? min + "分" : ""}
        </Text>
      </ByText>

      <View className="mt-2 text-xs text-third">
        <ByText size="xs" type="third">
          <Moment value={workerStartDate} />
          ～
          <Moment value={workerEndDate} />
        </ByText>
      </View>
    </View>
  );
};
